package com.yowasa.xiuxian.engine.battle.strategy.drop.wood;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.entity.enums.StageEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import com.yowasa.xiuxian.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name="繁盛的枯荣",upAbility = 4,needTravel = 1000)
@Order(1004)
@Component
public class FanShengKuRong extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;
    @Override
    public ElementEnum getElement() {
        return ElementEnum.WOOD;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int orgAtk = first.getBattleInfo().getSpell() ;
        int def = second.getBattleInfo().getRes();
        int dmg = (int) (battleHelper.calSpell(orgAtk,def) * 1.5 + (first.getBattleInfo().getHp() * 0.1));

        first.getBattleInfo().setCmp((int) (first.getBattleInfo().getCmp() - (first.getBattleInfo().getMp() * 0.05)));
        first.getBattleInfo().setChp((int) (first.getBattleInfo().getChp() - (first.getBattleInfo().getHp() * 0.1)));
        battleHelper.autoAction(this, first, second, content, dmg, "繁盛的枯荣");
        first.getCd().put("繁盛的枯荣", 2);
    }

    @Override
    public void limit(UserBO user) {
        if (user.getElement().get("木") < XiuxianConstants.DEFAULT_ELEMENT_ACTIVITY) {
            throw new HandlerException("学习/使用繁盛的枯荣必须具有木灵根");
        }
    }
    @Override
    public String limitDesc() {
        return "具有木灵根";
    }

    @Override
    public String desc() {
        return "消耗自身10%的血量和5%蓝量，给对方造成1.5倍的法术和本次燃烧血量的伤害，cd 1回合";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        Integer cd = user.getCd().get("繁盛的枯荣");
        if (cd != null && cd > 0) {
            return false;
        }
        int costMp = user.getBattleInfo().getMp() / 20;
        if (user.getBattleInfo().getCmp() < costMp) {
            return false;
        }
        int sostHp = user.getBattleInfo().getHp() / 10;
        if (user.getBattleInfo().getChp() < sostHp) {
            return false;
        }
        return true;
    }
}
